export default {
    /*处理推广页面的数据*/
    dealPromotionData (state, data) {
        let temp = {};
        let tempList = [];
        let that = this;
        data.list.forEach((value, index) => {
            temp = {
                dataInfo: value.dataInfo,
                hadLiked: value.hadLiked,
                belongStoreInfo: value.belongStoreInfo,
                directChannel: value.directChannel,
                mediaContents: value.promotionInfo.mediaContents,
                mediaType: value.promotionInfo.mediaType,
                paginationType: 2,
                likeType: 2,
                id: value.promotionInfo.promotionId,
                isNeedContentShare: false,
                storeId: that.storeId,
                isNeedLocation: true,
                isNeedLike: true,
                isNeedComment: false,
                isNeedShare: true,
                isNeedServer: true,
            };
            tempList.push(temp);
            that.commit('couponsRedDeal', { value, index })
        });
        state.promotion.commont = tempList;
        this.commit('dealPromotionMsg', data);
    },
    dealPromotionMsg (state, data) {
        let msg = data.list;
        let that = this;
        let tempList = [];
        let tempStoreMsg = {};
        let promotionInfo = {};
        let promotionFloats = [];
        msg.forEach((value, index) => {
            promotionInfo = value.promotionInfo;
            promotionFloats = value.promotionFloats;
            if (!(Array.isArray(promotionFloats) && promotionFloats.length > 0 && promotionFloats[0])) {
                promotionFloats = [{}]
            }
            let actInfo = promotionFloats[0].actInfo;
            tempStoreMsg = {
                "promotionId": promotionInfo.promotionId,
                "mediaId": promotionInfo.promotionId,
                "mediaType": promotionInfo.mediaType,
                "mediaContents": promotionInfo.mediaContents,
                "poster": promotionInfo.poster,
                "hasWelPacket": !!promotionInfo.packetInfo,
                "welPacketId": promotionFloats[0].welPacketId,
                "packetInfo": promotionFloats[0].packetInfo,
                "welPacketIco": promotionFloats[0].floatIco,
                "hasTicket": !!promotionFloats[0].templateTickets,
                // "ticketTemplateIds": promotionInfo.ticketTemplateIds,
                "templateTickets": promotionFloats[0].templateTickets,
                "ticketIco": promotionFloats[0].floatIco,
                "actInfo": actInfo,
                "hasActivity": !!actInfo,
                "actType": promotionFloats[0].actType,
                "actKey": actInfo && actInfo.actKey ? actInfo.actKey : 0,
                "actTitle": actInfo && actInfo.actTitle ? actInfo.actTitle : '',
                "actUrl": actInfo && actInfo.actUrl ? actInfo.actUrl : '',
                "actIco": promotionFloats[0].floatIco,
                "belongStoreInfo": value.belongStoreInfo,
                "shareBodyInfo": value.shareBodyInfo,
            };
            tempList.push(tempStoreMsg);
            msg[index].promotionInfo.mediaId = msg[index].promotionInfo.promotionId;
            state.promotion.message.list.push(msg[index].promotionInfo);
        })
        let tempObj = {
            // headerMsg: 'moudule1',
            list: tempList,
        }
        state.promotion.message = Object.assign({}, state.promotion.message, tempObj);
    },
    couponsRedDeal (state, obj) {
        if (!obj) {
            return
        }
        let index = obj.index || 0;
        obj = obj.value || {};
        let tempPromotionList = obj.promotionFloats;
        let couponsProps = [];
        let tempTicketObj = {};
        let tempObjItem = {};
        /*卡券*/
        if (Array.isArray(tempPromotionList) && tempPromotionList.length > 0) {
            tempPromotionList.forEach((promotionItem, promotionIndex) => {
                if (promotionItem.templateTickets) {
                    for (let value in promotionItem.templateTickets) {
                        let tempObjItem = {
                            templateId: promotionItem.templateTickets[value].templateTicketId,
                            state: promotionItem.templateTickets[value].state,
                            startTime: promotionItem.templateTickets[value].startTime,
                            endTime: promotionItem.templateTickets[value].endTime,
                            ticketType: promotionItem.templateTickets[value].type,
                            scope: promotionItem.templateTickets[value].scope,//使用范围
                            storeIcon: promotionItem.templateTickets[value].logo,
                            promotionId: promotionItem.promotionId,
                            condition: promotionItem.templateTickets[value].condition
                        };
                        couponsProps.splice(value, 1, tempObjItem);
                    }
                    /*红包*/
                } else if (promotionItem.packetInfo) {
                    let temp = {};
                    // temp.rule = ['邀好友开红包','每成功邀请1次<br/>可领1次红包','进APP提现'];
                    // 普通红包且没有领取的时候只显示领取//是否有可领金额在组件内部处理
                    if (promotionItem.packetInfo.welPacketType == 0) {
                        temp.showGetMoneyBtn = false;//红包提现按钮
                        temp.showGetBtn = true;
                        temp.showShareBtn = false;
                        /*助力红包*/
                    } else if (promotionItem.packetInfo.welPacketType == 1) {
                        /*成长红包*/
                        temp.showGetMoneyBtn = false;//红包提现按钮
                        temp.showGetBtn = true;
                        temp.showShareBtn = false;
                    } else if (promotionItem.packetInfo.welPacketType == 2) {
                        temp.showGetMoneyBtn = false;//红包提现按钮
                        temp.showGetBtn = true;
                        temp.showShareBtn = false;
                    }

                    let tempObjItem = {
                        title: promotionItem.packetInfo.title,
                        redTypeState: promotionItem.packetInfo.welPacketType,
                        rule: [],
                        myPacketInfo: {
                            receivedAmount: promotionItem.packetInfo.receivedAmount,//
                            welPacketId: promotionItem.packetInfo.welPacketId,
                            completeReceived: promotionItem.packetInfo.canReceive,
                            canReceiveAmount: promotionItem.packetInfo.canReceiveAmount,//
                            showReceivedAmount: promotionItem.packetInfo.showReceivedAmount,
                            canReceive: promotionItem.packetInfo.canReceive,
                            lastTimeMillis: promotionItem.packetInfo.lastTimeMillis,//
                            invitedNum: promotionItem.packetInfo.invitedNum,//已经邀约人数
                            waitInvitedNum: promotionItem.packetInfo.waitInvitedNum,//剩余邀请人数
                            packetHelpers: promotionItem.packetInfo.packetHelpers//增长金额
                        },
                    };
                    couponsProps.splice(index, 1, tempObjItem);
                } else if (!(promotionItem.packetInfo || promotionItem.templateTickets)) {
                    couponsProps.splice(index, 1, {});
                }
            })
        }
        tempTicketObj = {
            isShow: false,
            couponsProps,
        }
        state.promotion.couponsList.splice(index, 1, tempTicketObj);
    }
}